<?php
require_once(str_replace("\\", "/", dirname(__FILE__)) . "/../config.inc.php");
$page_id = "pages.stockdefaultpage";

$user = $context->getBean("modules.accounts.business.user");
$preferences = $user->getPreferences();
$global_default_page = $preferences["global_default_page"]["value"];
$global_default_page = $global_default_page ? $global_default_page : "pages.globaldefaultpage";
$isEntry = ($page_id == $global_default_page) ? "true" : "false";

$page_skin = $preferences["page_skin"]["value"];
$page_skin = $page_skin ? $page_skin : "default";
$page_container_width = $preferences["page_container_width"]["value"];
$page_container_width = $page_container_width ? $page_container_width : "760px";

/*- 财经有关信息 -*/
$finance = $context->getBean("modules.finance.business.finance");
$combinations = $finance->getUserCombinations();
$investmentTypes = $finance->getInvestmentTypes();

$symbol = trim($_POST["add_investmen_symbol"]);
$type = trim($_POST["add_investmen_type"]);
$date = strtotime(trim($_POST["add_investmen_date"]));
$quantity = (int)trim($_POST["add_investmen_quantity"]);
$cost = (int)trim($_POST["add_investmen_cost"]);
$note = trim($_POST["add_investmen_note"]);     
if(strlen($symbol) > 0){
    $combinationId = $finance->addStock($symbol);
    if(($combinationId > 0) && strlen($quantity) > 0){
        $finance->addInvestment($symbol, $combinationId, $type, $date, $quantity, $cost, $note);    
    }
	//header('Location: ./index.php');
	exit;
}

$page = $context->getBean($page_id);
$page->assign("page_id", $page_id);
$page->assign("isEntry", $isEntry);
$page->assign("isDefault", "false");
$page->assign("page_skin", $page_skin);
$page->assign("page_container_width", $page_container_width);

$page->assign("add_investmen_action", $_SERVER['PHP_SELF']);
$page->assign("investmentTypes", $investmentTypes);
$page->assign("combinations", $combinations);
$page->render();
?>
